<template>
  <template v-if="type === 'config-mobile' || type === 'mobile'">
    <RadioInput
      v-if="config.selectShowType"
      v-model="input"
      :label="config.title"
      :options="options"
      :required="config.required"
      @change="onChange"
    />
    <PickerInput
      v-else
      v-model="input"
      :label="config.title"
      :options="options"
      :required="config.required"
      @change="onChange"
    />
  </template>
  <div v-if="type === 'config-table' || type === 'table'" class="v-form-item-wrapper">
    <div class="form-item">
      <el-radio-group v-if="config.selectShowType" v-model="input" @change="onChange">
        <el-radio v-for="option in config.options" :key="option" :label="option">
          {{ option }}
        </el-radio>
      </el-radio-group>
      <el-select v-else v-model="input" :placeholder="config.placeholder" @change="onChange">
        <el-option v-for="option in config.options" :key="option" :label="option" :value="option" />
      </el-select>
      <div v-if="config.required" class="required">*</div>
    </div>
    <pre v-if="config.tips"><i class="icon iconfont">&#xe77e;</i>{{ config.tips }}</pre>
  </div>
</template>

<script setup lang="ts">
import PickerInput from '../../components/vant/PickerInput.vue'
import RadioInput from '../../components/vant/RadioInput.vue'
const emits = defineEmits(['update'])
const props = defineProps<{
  id: string
  tdId: string
  formType: string
  formTypeName: string
  config: any

  type: string // config table mobile print
  formValue: string
}>()
const input = ref<string>('6')
const options = computed(() => {
  return props.config.options.map((el) => {
    return {
      label: el,
      value: el
    }
  })
})
const onChange = () => {
  emits('update', input.value)
}
onMounted(() => {
  input.value = props.formValue
})
</script>
